package com.easy.dn.ui.main.model;

import com.easy.dn.api.Api;
import com.easy.dn.api.ApiService;
import com.easy.dn.bean.JobAddressBean;
import com.easy.dn.bean.SearchResumeBean;
import com.easy.dn.ui.main.contract.SearchResumeContract;
import com.easy.dn.utils.DnUtils;

import java.util.List;
import java.util.Map;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by 丁宁
 * on 2017/7/31.
 */

public class SearchResumeModel implements SearchResumeContract.Model {

    @Override
    public Observable<SearchResumeBean> getResumeList(Map<String , String> map) {
        return Api.getInstance().getProxy(ApiService.class)
                .getSearchResumeList(Api.getCacheControl(),map)
                .map(new Func1<SearchResumeBean, SearchResumeBean>() {
            @Override
            public SearchResumeBean call(SearchResumeBean resumeBean) {
                List<JobAddressBean> addressList;
                        if (DnUtils.list == null) {
                            addressList = DnUtils.getAddressList();
                        } else {
                            addressList = DnUtils.list;
                        }
                        for (JobAddressBean bean : addressList) {
                            for (SearchResumeBean.RowsBean recentBean : resumeBean.getRows()) {
                                String city = recentBean.getCity();
                                if (bean.getCode().equals(city)) {
                                    recentBean.setCityName(bean.getName());
                                }
                            }
                        }
//                        return recentBeen;
                return resumeBean;
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}
